package com.kkang.ch2.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.stereotype.Component;

/**
 * 模拟 事件触发器
 *
 * @author yongk_liu
 **/
@Component
public class DemoEventPublisher {

    @Autowired
    ApplicationContext applicationContext;//注入Application，用来发布事件

    public void publish(String msg) {
        ApplicationEvent event = new DemoEvent(this, msg);
        applicationContext.publishEvent(event);//向整个容器发布DemoEvent事件
    }

}
